var React = require('react');


var Main = require('./main.js');
var Login = require('./login.js');
//管理主模块

var Application = React.createClass({
    getInitialState:function () {
        return {
            hiddenLogin:false,//页面初始化显示登录页
            username:null,
            localStream:null


        }

    },
    getDefaultProps:function () {
        return {
            serverAddress : 'http://139.196.12.59:8095',
            p2p:new Woogeen.PeerClient({
            iceServers : [{
                urls : "stun:139.196.106.6:3478"
            },{
                urls : ["turn:139.196.106.6:3478?transport=udp","turn:139.196.106.6:3478?transport=tcp"],
                credential : "kurento",
                username : "kurento"
            }]
        })
        };

    },
    Login:function (username) {

        if(username && username.length>0){
            this.setState({hiddenLogin:!this.state.hiddenLogin,username:name});
            this.props.p2p.connect({host:this.props.serverAddress,token:name});  // Connect to peer server

        }else{
            alert("请输入有效的用户名!");
        }

    },
    render:function () {
        if(this.state.hiddenLogin){//已经隐藏了登录
            return   <Main contacts={this.props.contacts} />

        }else{
            return   <Login Login={this.Login} />

        }

    }

})


module.exports = Application;